package com.shop2cn.iapi.agentproducts.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.DeleteCatalogPropertyBean;
import com.shop2cn.iapi.agentproducts.parameter.SaveCatalogPropertyBean;
import com.shop2cn.iapi.agentproducts.service.DeleteCatalogPropertyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.TestDataManager;

/**
*删除规格属性
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DeleteCatalogProperty{
	private static DeleteCatalogPropertyBean deletecatalogpropertyBean;
	private static DeleteCatalogPropertyCall deletecatalogpropertyCall;
	private final static int sellerId = AgentUsers.rootUserId;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除规格属性");
	}

	@Before
	public void caseUp() {
		deletecatalogpropertyBean=new DeleteCatalogPropertyBean();
		deletecatalogpropertyCall=new DeleteCatalogPropertyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deletecatalogpropertyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	public void verifyDB(DeleteCatalogPropertyBean deletecatalogpropertyBean){
		YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
		List<Map> mapList = ymtProductsIWapper.selectUserCatalogProperty(deletecatalogpropertyBean.getPropertyName(),deletecatalogpropertyBean.getPropertyValue());
		Logger.debug(mapList);
		Logger.verifyEquals(-1,Integer.parseInt(mapList.get(0).get("Action").toString()),"验证action");
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DeleteCatalogProperty_01() {
		Logger.start(true,"删除规格属性");
		try {
			SaveCatalogPropertyBean saveCatalogPropertyBean = AddAgentProductCallService.initSaveCatalogPropertyBean(sellerId);
			saveCatalogPropertyBean.getPropertyList().get(0).setName("Testdel_"+TestDataManager.getRandomNum(6));
			saveCatalogPropertyBean.getPropertyList().get(0).setValue("del_"+TestDataManager.getRandomNum(6));
			AddAgentProductCallService.SaveCatalogProperty(saveCatalogPropertyBean);
			deletecatalogpropertyBean.setUserId(sellerId);
			deletecatalogpropertyBean.setPropertyName(saveCatalogPropertyBean.getPropertyList().get(0).getName());
			deletecatalogpropertyBean.setPropertyValue(saveCatalogPropertyBean.getPropertyList().get(0).getValue());
			deletecatalogpropertyCall.setData(deletecatalogpropertyBean);
			deletecatalogpropertyCall.callService();			
			Logger.verifyEquals("200",deletecatalogpropertyCall.getString("code"),"验证code");
			verifyDB(deletecatalogpropertyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DeleteCatalogProperty_02() {
		Logger.start(true,"删除规格属性,用户id为空");
		try {
			SaveCatalogPropertyBean saveCatalogPropertyBean = AddAgentProductCallService.initSaveCatalogPropertyBean(sellerId);
			AddAgentProductCallService.SaveCatalogProperty(saveCatalogPropertyBean);
			deletecatalogpropertyBean.setUserId(0);
			deletecatalogpropertyBean.setPropertyName(saveCatalogPropertyBean.getPropertyList().get(0).getName());
			deletecatalogpropertyBean.setPropertyValue(saveCatalogPropertyBean.getPropertyList().get(0).getValue());
			deletecatalogpropertyCall.setData(deletecatalogpropertyBean);
			deletecatalogpropertyCall.callService();
			Logger.verifyEquals("400",deletecatalogpropertyCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}